package com.base.genid.config;

import com.base.genid.worker.DisposableWorkerIdAssigner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.io.Serializable;

@Configuration
@PropertySource(value = {"classpath:uid/uid-generator-spring.yml"}, ignoreResourceNotFound = true)
@Component
public class UidGeneratorConfig implements Serializable {

    @Value("${timebits}")
    private int timeBits = 29;

    @Value("${workerbits}")
    private int workerBits = 21;

    @Value("${seqbits}")
    private int seqBits = 13;

    @Value("${epochstr}")
    private String epochStr = "2016-09-20";

    @Value("${boostPower}")
    private int boostPower = 3;

    @Value("${paddingFactor}")
    private int paddingFactor = 50;

    @Value("${scheduleInterval}")
    private long scheduleInterval = 60;

    @Bean("disposableWorkerIdAssigner")
    public DisposableWorkerIdAssigner disposableWorkerIdAssigner(){
        DisposableWorkerIdAssigner disposableWorkerIdAssigner = new DisposableWorkerIdAssigner();
        return  disposableWorkerIdAssigner;
    }

    public int getBoostPower() {
        return boostPower;
    }

    public int getPaddingFactor() {
        return paddingFactor;
    }

    public int getSeqBits() {
        return seqBits;
    }

    public int getTimeBits() {
        return timeBits;
    }

    public int getWorkerBits() {
        return workerBits;
    }

    public long getScheduleInterval() {
        return scheduleInterval;
    }

    public String getEpochStr() {
        return epochStr;
    }

    public void setBoostPower(int boostPower) {
        this.boostPower = boostPower;
    }

    public void setEpochStr(String epochStr) {
        this.epochStr = epochStr;
    }

    public void setPaddingFactor(int paddingFactor) {
        this.paddingFactor = paddingFactor;
    }

    public void setScheduleInterval(long scheduleInterval) {
        this.scheduleInterval = scheduleInterval;
    }

    public void setSeqBits(int seqBits) {
        this.seqBits = seqBits;
    }

    public void setTimeBits(int timeBits) {
        this.timeBits = timeBits;
    }

    public void setWorkerBits(int workerBits) {
        this.workerBits = workerBits;
    }

    @Override
    public String toString() {
        return "UidGeneratorConfig{" +
                "timeBits=" + timeBits +
                ", workerBits=" + workerBits +
                ", seqBits=" + seqBits +
                ", epochStr='" + epochStr + '\'' +
                ", boostPower=" + boostPower +
                ", paddingFactor=" + paddingFactor +
                ", scheduleInterval=" + scheduleInterval +
                '}';
    }
}
